import {Component, Input, Output, EventEmitter} from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {HttpServies} from '../../providers/http-servies';
import {WorkPage} from "../work/work";

@Component({
    selector: 'page-contact',
    templateUrl: 'contact.html',
    providers:[HttpServies]
})
export class ContactPage {
    @Input() pageNum:number=1;//当前第几页,默认1
    @Output() pageNumChange = new EventEmitter<any>();
    ceil(num){
        return Math.ceil(num);
    }
    userInfo={
        'keyword':'',
        'jobinten':'',
        'jobfield':'',
        'companyname':'',
        'title':'',

    }

    dataJson:any=[];
    homeJson:any=[];
    placeJson:any=[];
    plaJson:any=[];
    fulltime = 0;
    jobinten="";
    jobfield="";
    keyword="";
    value=0;
    mingqi=0;
    companyname='';
    title='';
/*
*
* 页面加载项
*
* */

    ionViewDidLoad() {
        this.getsossokuan();
        this.getInfo();
        this.getsInfo();
    }
    constructor(public navCtrl: NavController, private http:HttpServies,public navParams: NavParams) {
        this.fulltime = this.navParams.get('fulltime');
        this.mingqi = this.navParams.get('mingqi');
        this.keyword = this.navParams.get( 'param');
        this.jobinten = this.navParams.get( 'jobinten');
    }
    //工作职位详情跳转
    woPage(jobinten,companyname){
        this.navCtrl.push(WorkPage,{jobinten,companyname});
    }




    /*
    *
    * 首页跳转方法
    *
    * */
    getsossokuan() {
        if (this.keyword != null) {
            var keyword = this.keyword;
            this.http.httpPost('/Home/job/company', keyword)
                .then(res => {//成功
                    if (res && res.code == 1) {
                        console.log(res.msg);
                        this.dataJson = res.data;
                    } else {
                        this.http.showErro('暂时没有这个职位');
                    }
                })
        }else if(this.fulltime!=null){
            var fulltime = "fulltime="+this.fulltime;
            this.http.httpPost('/Home/index/fulltime',fulltime)
                .then(res => {//成功
                    if (res && res.code == 1) {
                        console.log(res.msg);
                        this.dataJson = res.data;
                    }else {
                        this.http.showErro(res.msg);
                    }
                })
        }else if (this.jobinten!=null){
            var jobinten='jobinten='+this.jobinten;
                this.http.httpPost('/home/job/wor',jobinten)
                    .then(res => {//成功
                        if (res && res.code == 1) {
                            console.log(res.msg);
                            this.dataJson = res.data;
                        }else {
                            this.http.showErro(res.msg);
                        }
                    })
        }else if (this.mingqi ==1){
                this.http.httpPost('/Home/index/famous')
                    .then(res => {//成功
                        if (res && res.code == 1) {
                            console.log(res.msg);
                            this.dataJson = res.data;
                        }else {
                            this.http.showErro(res.msg);
                        }
                    })
        }else {
            this.http.httpPost('/Home/job/index')
                .then(res => {//成功
                    if (res && res.code == 1) {
                        console.log(res.msg);
                        this.dataJson = res.data;
                    } else {
                        this.http.showErro(res.msg);
                    }
                })
        }
    }
    btnClick(pageNum){
        this.pageNum = pageNum;
        var param = "num="+this.pageNum;
        this.http.httpPost('/Home/job/index',param)
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.dataJson = res.data;
                }
            })
    }


    /*
    * 找工作/地区/职务/筛选方法
    *
    * */
    switType(){
        var param = "title="+this.userInfo.title +"&jobfield="+this.userInfo.jobfield
        this.http.httpPost('/Home/job/work',param)
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.dataJson = res.data;
                }else {
                    this.http.showErro(res.msg);
                }
            })
    }
    /*
    * 找工作搜索框方法
    *
    * */
    SuosType(){
        var param = "keyword="+this.userInfo.keyword;
        this.http.httpPost('/home/job/company',param)
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.dataJson = res.data;
                }else {
                    this.http.showErro(res.msg);
                }
            })
    }
/*
* 地区筛选
* */
    getInfo(){
        this.http.httpPost('/Home/job/place_cartridge')
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.placeJson = res.data;
                }else {
                    this.http.showErro(res.msg);
                }
            })
    }
    /*
     * 职位筛选
     * */
    getsInfo(){
        this.http.httpPost('/Home/job/work_cartridge')
            .then(res => {//成功
                if (res && res.code == 1) {
                    console.log(res.msg);
                    this.plaJson = res.data;
                }else {
                    this.http.showErro(res.msg);
                }
            })
    }




}
